<template>
  <div class="musicList">
    <div class="musicTop">
      <div class="title">发现好歌单</div>
      <div class="more">查看更多</div>
    </div>
    <div class="musicContent">
      <van-swipe
        :loop="false"
        :width="120"
        :show-indicators="false"
        class="mySwiper"
      >
        <van-swipe-item v-for="item in musicList" :key="item.id">
          <router-link :to="{ name: 'ItemMusic', query: { id: item.id } }">
            <img :src="item.picUrl" alt="" />
            <div class="name">{{ item.name }}</div>
            <div class="play">
              <svg class="icon" aria-hidden="true" stroke="#ffffff;">
                <use xlink:href="#icon-bofang_o"></use>
              </svg>
              <span>{{ changeNum(item.playCount) }}</span>
            </div>
          </router-link>
        </van-swipe-item>
      </van-swipe>
    </div>
  </div>
</template>
<script setup>
import { getMusicList } from '@/request/api/home.js'
import { onMounted, ref } from 'vue'
const musicList = ref([])
onMounted(async () => {
  const res = await getMusicList()
  console.log(res)
  musicList.value = res.data.result
})
function changeNum(num) {
  if (num >= 100000000) {
    return (num / 100000000).toFixed(1) + '亿'
  }
  if (num >= 10000) {
    return (num / 10000).toFixed(1) + '万'
  }
  return num
}
</script>
<style lang='scss' scoped>
.musicList {
  margin-top: 0.4rem;
  .musicTop {
    display: flex;
    justify-content: space-between;
    align-items: center;
    .title {
      font-weight: 800;
      font-size: 0.36rem;
    }
    .more {
      width: 1.6rem;
      height: 0.65rem;
      line-height: 0.65rem;
      text-align: center;
      border: 1px solid #e0e0e0;
      border-radius: 25%;
    }
  }
  .musicContent {
    height: 4rem;
    margin-top: 0.2rem;
    .mySwiper {
      height: 100%;
      .van-swipe-item {
        position: relative;
        height: 100%;
        margin-right: 0.3rem;
        .play {
          position: absolute;
          display: flex;
          align-items: center;
          top: 0.04rem;
          right: 0.1rem;
          height: 0.6rem;
          color: #ffffff;
          .icon {
            color: #ffffff;
          }
          span {
            margin: 0;
            display: inline-block;
          }
        }
        img {
          width: 100%;
        }
      }
    }
  }
}
</style>
